// pages/component/city-scroll/index.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    cities: {
        type: Array,
        value: [
          {name: '北京'}, {name: '上海'}, 
          {name: '广州'}, {name: '深圳'},
          // 其他城市...
        ]
      }
  },

  /**
   * 组件的初始数据
   */
  data: {
    activeIndex: 0,
    scrollLeft: 0,
    lastScrollTime: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onScroll(e) {
        const now = Date.now()
        if (now - this.data.lastScrollTime > 200) {
          this.playSound()
          this.setData({ lastScrollTime: now })
        }
        
        // 计算当前居中项
        const scrollLeft = e.detail.scrollLeft
        this.setData({ scrollLeft })
      },
      
      selectCity(e) {
        const index = e.currentTarget.dataset.index
        this.setData({ 
          activeIndex: index,
          scrollLeft: index * 100 // 根据实际item宽度调整
        })
        this.triggerEvent('change', this.data.cities[index])
      },
      
      playSound() {
        const audioCtx = wx.createInnerAudioContext()
        audioCtx.src = '/assets/sound/scroll.mp3'
        audioCtx.play()
      }
  }
})